package main;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class CodeViewer extends JFrame implements ActionListener{
	
	private String code;
	private JTextArea area = new JTextArea();
	private JButton save = new JButton("Save");
	private QNote parent;
	
	/**
	 * Creates a new screen with a text box and save button, to manually edit the score code
	 * @param s Score code from the current score	
	 * @param q QNote object
	 */
	public CodeViewer(String s, QNote q){
		super("Score File");
		code = s;
		parent = q;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(500,500);
		area.setText(code);
		setLayout(new BorderLayout());
		
		JPanel pane = new JPanel();
		pane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		pane.add(save);
		
		add(area, BorderLayout.CENTER);
		add(pane, BorderLayout.SOUTH);
		save.addActionListener(this);
		setResizable(false);
		setLocation(parent.WIDTH+10, 0);
		setLocationRelativeTo(parent);
		setVisible(true);
	}

	@Override
	/**
	 * Sends the score code to be interpretted
	 */
	public void actionPerformed(ActionEvent arg0) {
		String newCode = area.getText();
		parent.removeScore(parent.getCurrentScore());
		parent.interpret(newCode);
		this.dispose();
	}
}
